<template>
  <div>
    <div>
      <iframe :src="props.bunkerthreeUrl" ref="penlinMyIframe" width="100%" height="800px;" frameborder="0"
        @load="getLatestyorkRecord(props.bunkerId)"></iframe>
    </div>
  </div>
</template>
<script setup lang="ts">
import { ref, onMounted } from "vue";
import { getTheLatestyorkRecord } from "./fuelWorkTInventoryInfo";
const penlinMyIframe = ref<HTMLIFrameElement | undefined>(undefined);
const props = defineProps<{
  bunkerId?: number;
  bunkerNo?: number;
  /** 三维地址 */
  bunkerthreeUrl: string;
  /** 附件地址 */
  fileBaseUrl: string;
}>();
onMounted(() => {
  // if (props.bunkerId?.toString()) {
  //   getLatestyorkRecord(props.bunkerId);
  // }
});
/** 获取记录 */
function getLatestyorkRecord(bunkerId?: number) {
  if (!bunkerId?.toString()) {
    return;
  }
  getTheLatestyorkRecord(bunkerId).then((res: any) => {
    if (res.code == 200) {
      const currentData = res.data;
      var fileNameJson =
        props.fileBaseUrl +
        props.bunkerNo +
        "Stockyard" +
        "/" +
        currentData.fileName +
        "/" +
        currentData.fileName +
        ".json";

      const paraData = [
        {
          yardNumber: currentData.parent_bunker_id,
          fileList: [fileNameJson]
        }
      ];
      const iframe = penlinMyIframe.value;
        setTimeout(() => {
        const jfile = JSON.stringify(paraData);
            console.log(jfile);
        iframe?.contentWindow?.postMessage(
          "FileAddress$" + jfile,
          props.bunkerthreeUrl
        );
      }, 1000);
    }
  })
}
</script>
